package LeetCode.month02.day52;

import java.util.*;

public class No966 {
    public static void main(String[] args) {
        Map<String,String> map = new TreeMap<>();
        map.put("  ","12");
        System.out.println(map.get("  "));
        System.out.println(Arrays.toString(spellchecker(new String[]{"ae","aa"},new String[]{"UU"})));
    }
    public static String[] spellchecker(String[] wordlist, String[] queries) {
//        Set<String> set = new HashSet<>(Set.of(wordlist));
        Set<String> set = new HashSet<>();
        Map<String,String> map = new HashMap<>();
        Map<String,String> map2 = new HashMap<>();
        for (String s : wordlist) {
            set.add(s);
            if(!map.containsKey(s.toLowerCase())) {
                map.put(s.toLowerCase(), s);
            }
            String key = delete(s);
            if(!map2.containsKey(key)) {
                map2.put(key,s);
            }
        }
        System.out.println("set = " + set);
        System.out.println("map = " + map);
        System.out.println("map2 = " + map2);
        int n = queries.length;
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            String s = queries[i];
            String s1 = delete(s);
            if(set.contains(s)){
                res[i]=s;
            }else if(map.containsKey(s.toLowerCase())){
                res[i] = map.get(s.toLowerCase());
            }else if(map2.containsKey(s1)){
                res[i]=map2.get(s1);
            }else{
                res[i] = "";
            }
        }
        System.out.println(Arrays.toString(queries));
        return res;
    }
    public static String delete(String s){
        return s.toLowerCase().replaceAll("[aeiou]", "*");
    }
}
